# -*- coding: utf-8 -*-
# 公共使用函数

import os, time
import configparser
from tools.logger import Logger

logger = Logger(logger="TestWeb").getlog()
base_url = os.path.abspath('.')

#获取config配置文件
def getConfig(section, key):
    config = configparser.ConfigParser()
    path = base_url + "/config/config.ini"
    config.read(path)
    return config.get(section, key)

def picture(driver):
    try:
        picture_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
        directory_time = time.strftime("%Y-%m-%d", time.localtime(time.time()))
        File_Path = base_url + "/pictures/" + str(directory_time)
        if not os.path.exists(File_Path):
            os.makedirs(File_Path)
            logger.info("目录新建成功：%s" % File_Path)
        else:
            logger.info("目录已存在！！！")
        try:
            file_url = base_url + "/pictures/" + str(directory_time) + '/' + str(picture_time) + '.png'
            flag = driver.save_screenshot(file_url)
            logger.info("截图成功：%s" % flag)
        except BaseException as pic_msg:
            logger.error("截图失败：%s" % pic_msg)
    except BaseException as msg:
        logger.error("新建目录失败：%s" % msg)




